import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtV6mQeoyQXKkJA378S4A\n' +
  'EC7O3H61ixDafQHotqFWV8Id7HNtMiPxRBIRCAzssj/6kN+lV5nGhenryfJagQKa\n' +
  'O2EFm92oKquxh7n92Vq4G7J+WnnFLe2qBj6wpM/ayiQMWSxAJId4w7UupJnkLKtP\n' +
  '7eCt9ghOmhlYHsSrq4/3judb1bvGzTBuu9TGBQPHv2t091ZmX95WWNSL4V3O2zP+\n' +
  'A+BkUHH/56dIOQISWOfKHjhXFmedxUagb99IwavESB9x5GVvsClKt1sdzU1AKoOr\n' +
  '8NxZsNnYpLGDkgQkIgGoxcz1mKDfOz7uAErPMsYx8npXQh7zFUO/4h3kO9fDz9O3\n' +
  'ZwIDAQAB'

const privateKey = 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC1XqZB6jJBcqQk\n' +
  'DfvxLgAQLs7cfrWLENp9Aei2oVZXwh3sc20yI/FEEhEIDOyyP/qQ36VXmcaF6evJ\n' +
  '8lqBApo7YQWb3agqq7GHuf3ZWrgbsn5aecUt7aoGPrCkz9rKJAxZLEAkh3jDtS6k\n' +
  'meQsq0/t4K32CE6aGVgexKurj/eO51vVu8bNMG671MYFA8e/a3T3VmZf3lZY1Ivh\n' +
  'Xc7bM/4D4GRQcf/np0g5AhJY58oeOFcWZ53FRqBv30jBq8RIH3HkZW+wKUq3Wx3N\n' +
  'TUAqg6vw3Fmw2diksYOSBCQiAajFzPWYoN87Pu4ASs8yxjHyeldCHvMVQ7/iHeQ7\n' +
  '18PP07dnAgMBAAECggEADsoJBJb0QiH3AHmjcacumiM2+wPaCdz18/uT3lCJmd5a\n' +
  'Uk2XOd90bPiMKvvi0SYmaGnUMbB4X7MTZwQ8HQj5Sp4+ttb8P36Am3CvImojWR7U\n'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TQ4+SFdvxx/i3Hio/ODwjYVLmj1OinqmXGlZZTXYJFxO6GnaPwx21YX6\n' +
  'M0gadKlT8IOXGLo9rfGcs7WqylbAsUMBVjSS3R/zfJzoeSdOPq+C4fVFseYaiIa1\n' +
  'amUEJLWNKRHLr92ZT4mUu+KJ'

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}

